package com.snail.cloud.model;

/**
 * @author MR.LHL
 * @date 2024/2/27
 */
public class ResultData<T> {

    private int code;
    private String msg;
    private T data;

    public static <T> ResultData<T> success() {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(0);
        resultData.setMsg("操作成功！");
        return resultData;
    }

    public static <T> ResultData<T> success(T data) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(0);
        resultData.setMsg("操作成功！");
        resultData.setData(data);
        return resultData;
    }

    public static ResultData<ResultCodeEnum> error(ResultCodeEnum resultCode) {
        ResultData resultData = new ResultData();
        resultData.setCode(resultCode.getCode());
        resultData.setMsg(resultCode.getMessage());
        return resultData;
    }

    public static <T> ResultData<T> error(ResultCodeEnum resultCode, T data) {
        ResultData resultData = new ResultData();
        resultData.setCode(resultCode.getCode());
        resultData.setMsg(resultCode.getMessage());
        resultData.setData(data);
        return resultData;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
